﻿// Type: System.Windows.DataObject
// Assembly: System.Windows, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
// Assembly location: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.Windows.dll

using System;
using System.Collections.Generic;
using System.IO;
using System.Security;

namespace System.Windows
{
  /// <summary>
  /// Provides a basic implementation of the <see cref="T:System.Windows.IDataObject"/> interface, which defines a format-independent mechanism for transferring data.
  /// </summary>
  public sealed class DataObject : IDataObject
  {
    private object _data;

    internal bool AllowDataAccess { get; set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="T:System.Windows.DataObject"/> class.
    /// </summary>
    public DataObject()
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="T:System.Windows.DataObject"/> class, with specified initial data.
    /// </summary>
    /// <param name="data">An object that represents the data to store in this data object.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception>
    public DataObject(object data)
    {
      throw new NotImplementedException();
    }

    /// <summary>
    /// Retrieves a data object in a specified format; the data format is specified by a string.
    /// </summary>
    /// 
    /// <returns>
    /// A data object that has the data in the specified format, or null if the data is not available in the specified format.
    /// </returns>
    /// <param name="format">A string that specifies what format to retrieve the data as. Use the constant <see cref="F:System.Windows.DataFormats.FileDrop"/>.</param><exception cref="T:System.ArgumentException"><paramref name="format"/> is not equivalent to <see cref="F:System.Windows.DataFormats.FileDrop"/>.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public object GetData(string format)
    {
      this.CheckDataAccess();
      if (format == DataFormats.FileDrop)
        return this._data;
      else
        throw new ArgumentException("format");
    }

    /// <summary>
    /// Retrieves a data object in a specified format; the data format is specified by a <see cref="T:System.Type"/> object. Always throws an exception.
    /// </summary>
    /// 
    /// <returns>
    /// Always throws an exception.
    /// </returns>
    /// <param name="format">A <see cref="T:System.Type"/> object that specifies the format in which to retrieve the data. </param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public object GetData(Type format)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Retrieves a data object in a specified format, optionally converting the data to the specified format. Always throws an exception.
    /// </summary>
    /// 
    /// <returns>
    /// Always throws an exception.
    /// </returns>
    /// <param name="format">A string that specifies the format in which to retrieve the data. </param><param name="autoConvert">true to attempt to automatically convert the data to the specified format; false for no data format conversion.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public object GetData(string format, bool autoConvert)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Checks to see whether the data is available in, or can be converted to, a specified format; the data format is specified by a string.
    /// </summary>
    /// 
    /// <returns>
    /// true if the data is in the specified format, and is not null. false if <paramref name="format"/> is not equivalent to <see cref="F:System.Windows.DataFormats.FileDrop"/>, or if the data is null.
    /// </returns>
    /// <param name="format">A string that specifies the format to check for. See the <see cref="T:System.Windows.DataFormats"/> class for a set of predefined data formats.</param><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public bool GetDataPresent(string format)
    {
      this.CheckDataAccess();
      if (format == DataFormats.FileDrop)
        return this._data != null;
      else
        return false;
    }

    /// <summary>
    /// Checks whether the data is available in, or can be converted to, a specified format. The data format is specified by a <see cref="T:System.Type"/> object. Always throws an exception.
    /// </summary>
    /// 
    /// <returns>
    /// Always throws an exception.
    /// </returns>
    /// <param name="format">A <see cref="T:System.Type"/> that specifies the format to check for.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public bool GetDataPresent(Type format)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Checks whether the data is available in, or can be converted to, a specified format. A Boolean flag indicates whether to check if the data can be converted to the specified format, if it is not available in that format. Always throws an exception.
    /// </summary>
    /// 
    /// <returns>
    /// Always throws an exception.
    /// </returns>
    /// <param name="format">A string that specifies the format to check for. See the <see cref="T:System.Windows.DataFormats"/> class for a set of predefined data formats.</param><param name="autoConvert">false to only check for the specified format; true to also check whether data stored in this data object can be converted to the specified format.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public bool GetDataPresent(string format, bool autoConvert)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Returns a list of all formats that the data in this data object is stored in, or can be converted to.
    /// </summary>
    /// 
    /// <returns>
    /// An array of strings, with each string specifying the name of a format supported by this data object.
    /// </returns>
    /// <exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public string[] GetFormats()
    {
      this.CheckDataAccess();
      if (this._data == null)
        return new string[0];
      return new string[1]
      {
        DataFormats.FileDrop
      };
    }

    /// <summary>
    /// Returns a list of all formats that the data in this data object is stored in. A Boolean flag indicates whether to also include formats that the data can be automatically converted to. Always throws an exception.
    /// </summary>
    /// 
    /// <returns>
    /// Always throws an exception.
    /// </returns>
    /// <param name="autoConvert">true to retrieve all formats that data in this data object is stored in, or converted to; false to retrieve only formats that data stored in this data object is stored in (excluding formats that the data is not stored in, but can be automatically converted to).</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public string[] GetFormats(bool autoConvert)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Stores the specified data in this data object and automatically converts the data format from the source object type. Always throws an exception.
    /// </summary>
    /// <param name="data">The data to store in this data object.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public void SetData(object data)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Stores the specified data in this data object, along with one or more specified data formats. The data format is specified by a string. Always throws an exception.
    /// </summary>
    /// <param name="format">A string that specifies what format to store the data in. See the <see cref="T:System.Windows.DataFormats"/> class for a set of predefined data formats.</param><param name="data">The data to store in this data object.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public void SetData(string format, object data)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Stores the specified data in this data object, together with one or more specified data formats. The data format is specified by a <see cref="T:System.Type"/> class. Always throws an exception.
    /// </summary>
    /// <param name="format">A <see cref="T:System.Type"/> that specifies the format in which to store the data.</param><param name="data">The data to store in this data object.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public void SetData(Type format, object data)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    /// <summary>
    /// Stores the specified data in this data object, together with one or more specified data formats. This overload includes a Boolean flag to indicate whether the data may be converted to another format on retrieval. Always throws an exception.
    /// </summary>
    /// <param name="format">A string that specifies the format in which to store the data. See the <see cref="T:System.Windows.DataFormats"/> class for a set of predefined data formats.</param><param name="data">The data to store in this data object.</param><param name="autoConvert">true to allow the data to be converted to another format on retrieval; false to prohibit the data from being converted to another format on retrieval.</param><exception cref="T:System.NotImplementedException">Not implemented.</exception><exception cref="T:System.Security.SecurityException">Attempted access in a mode other than Drop.</exception>
    public void SetData(string format, object data, bool autoConvert)
    {
      this.CheckDataAccess();
      throw new NotImplementedException();
    }

    [SecurityCritical]
    internal void SetDataInternal(string str)
    {
      if (string.IsNullOrEmpty(str))
        throw new ArgumentNullException("str");
      FileInfo[] fileInfo = this.CreateFileInfo(str);
      if (fileInfo == null)
        return;
      this._data = (object) fileInfo;
    }

    [SecurityCritical]
    private FileInfo[] CreateFileInfo(string str)
    {
      if (string.IsNullOrEmpty(str))
        return (FileInfo[]) null;
      string[] strArray = str.Split(new char[1]
      {
        '\n'
      });
      List<FileInfo> list = new List<FileInfo>();
      foreach (string uriString in strArray)
      {
        if (!string.IsNullOrEmpty(uriString))
        {
          Uri uri = new Uri(uriString);
          if (uri != (Uri) null)
          {
            FileInfo fileInfo = FileInfo.UnsafeCreateFileInfo(uri.LocalPath);
            if (fileInfo != null)
              list.Add(fileInfo);
          }
        }
      }
      return list.ToArray();
    }

    private void CheckDataAccess()
    {
      if (!this.AllowDataAccess)
        throw new SecurityException();
    }
  }
}
